<style>
<!--
.top_li{
	float:right !important;
	line-height: 2em;
}
#creat_div , #user_id-label , #is_edit-label , #is_add-label{
	display:none;
}

-->
</style>
<table id="user_lst">
</table>

<script type="text/javascript" src="<?php echo $this->pagePath;?>/js/swfupload/handlers.js"></script>
<script type="text/javascript" src="<?php echo $this->pagePath;?>/js/swfupload/swfupload.js"></script>
<script><!--
$(function() {
	window.grids = $("#user_lst").flexigrid({
		url: '<?php echo $this->pagePath;?>/product',
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'id', width : 20, sortable : true, align: 'center'},
			{display: '编号', name : 'code', width : 80, sortable : true, align: 'left'},
			{display: '条形码', name : 'barcode', width : 80, sortable : true, align: 'left'},
			{display: '名称', name : 'name_cn', width : 80, sortable : true, align: 'left'},
			{display: '英文名称', name : 'name_en', width : 80, sortable : true, align: 'left'},
			{display: '供货商', name : 'factory', width : 80, sortable : true, align: 'left'},
			{display: '规格', name : 'specification', width : 80, sortable : true, align: 'left'},
			{display: '图片', name : 'picture', width : 80, sortable : true, align: 'left'},			
			{display: '成本', name : 'cost', width : 80, sortable : false, align: 'left',process:gridHelper.Cash},
			{display: '售价', name : 'price', width : 80, sortable : true, align: 'left',process:gridHelper.Cash},
			{display: '创建时间', name : 'create_time', width : 80, sortable : true, align: 'left'},
			{display: '创建人', name : 'create_user', width : 80, sortable : true, align: 'left'},
			{display: '备注', name : 'note', width : 80, sortable : true, align: 'left', hide: true}
			
		],
		searchitems : [
            {display: '名称' ,name : 'name_cn', isdefault: true},	                     		
			{display: '编号' ,name : 'code'},	                     		
			{display: '供货商' ,name : 'factory'}	
		],
		buttons : [
			<?php if($this->allow('add','user','')){?>
			{name: '新增',bclass:"add", onpress : add},
			<?php } ?>
			<?php if($this->allow('edit','user','')){?>
			{name: '编辑',bclass:"edit", onpress : edit},
			<?php } ?>
			<?php if($this->allow('delete','user','')){?>
			{name: '删除',bclass:"delete", onpress : del},
			<?php } ?>
			/*{name: '编辑权限', onpress : edit_right},*/
			{separator: true}
		], 
		sortname: "id",
		sortorder: "asc",
		//singleSelect:true,//是否单选
		usepager: true,
		hideOnSubmit:false,//禁用遮照
		title: '产品列表',
		useRp: true,
		rp: 15,
		showTableToggleBtn: true,
		id:"accountsList",
		width: "99%",
		height: 310,
		onRowClick:function($e){
		},
		onRowDblclick:function(){
			//hideList();
		}
	}).show();
});
var

add = function(name,e){
	var top = $(this).offset().top;
	zendform.zendFormCreat(e,{
		url:"<?php echo $this->pagePath;?>/product/add",
		dialog:{
			title:"新增产品",
			width:818,
			height:338,
			position:[null,top]
		}
		,afterRenderCreatForm : function(){
			var upTagId = zendform.uploadTag($("#picture"));//设置swfupload附着的element
			zendform.appendSWFupload({
				"button_placeholder_id":upTagId//设置swfupload按钮附着的element，它来自上一条语句
				,file_types : "*.jpg;*.gif;*.png;*.bmp"
				,"upload_start_handler":function(){
					//开始上传
					zendform.uploadingTag($("#picture"));
				}
				,"upload_error_handler":function(file, errorCode, message){
					//上传出错时
					alert("上传错误："+message);
					$("#picture").next(".uploading").remove();
				}
			},{
				"ju_element":"picture" //通知上传的额外参数，这里的ju_element必须以ju开头，是返回值的复制element
			});
		}
	});
},
edit = function(name,e){
	id = $(e).find(".trSelected")[0].id.toString().replace("row","") || "0";
	var top = $(this).offset().top;
	zendform.zendFormCreat(e,{
		url:"<?php echo $this->pagePath;?>/product/edit/id/"+(id),
		dialog:{
			title:"修改产品",
			width:818,
			height:338,
			position:[null,top]
		}
		,afterRenderCreatForm : function(){
			var upTagId = zendform.uploadTag($("#picture"));//设置swfupload附着的element
			zendform.appendSWFupload({
				"button_placeholder_id":upTagId//设置swfupload按钮附着的element，它来自上一条语句
				,file_types : "*.jpg;*.gif;*.png;*.bmp"
				,"upload_start_handler":function(){
					//开始上传
					zendform.uploadingTag($("#picture"));
				}
				,"upload_error_handler":function(file, errorCode, message){
					//上传出错时
					alert("上传错误："+message);
					$("#picture").next(".uploading").remove();
				}
			},{
				"ju_element":"picture" //通知上传的额外参数，这里的ju_element必须以ju开头，是返回值的复制element
			});
		}
	});
},
del = function(name,e){
	var ids = $(e).find(".trSelected");
	var idsData = [];
	$.each(ids,function(i,n){
		var uid = n.id.toString().replace("row","") || "0";
		uid = uid;
		idsData.push(uid);
	});
	if(confirm("您确定要删除这"+ids.length+"项数据吗？")){
		$.ajax({
			"url":"<?php echo $this->pagePath;?>/product/del",
			"data":{id:idsData},
			"type":"POST",
			"success":function(data){
				if(data.status > 0){
					var randId = "id_" + Date.parse(new Date());
		        	window.grids.flexReload();
		        	$("<div id='"+randId+"'>"+data.msg+"</div>").dialog({title:"SUCCESS!",height: 140,modal: true});
		        	window.setTimeout(function(){$("#"+randId).dialog("close");},1200);
		        }else{
			        $("<div>ERROR!"+data.msg+"</div>").dialog({title:"ERROR!",height: 140,modal: true});
		        }
			},
			"error":function(){
		    	$("<div>ERROR!<br>服务错误！可能是网络忙！</div>").dialog({title:"ERROR!",height: 140,modal: true});
			}
		});
	}
};
--></script>
<div id="creat_div"></div>
<div id="edit_div"></div>